
<div class="container">

    <!--<div class="page-header"><div class="row"><h1 class="span12">Kontrolna tabla</h1></div></div>-->

    <div class="row">
        <div class="span6">
            <table id="hotelsList"></table> 
            <div id="hotelsPager"></div>     

        </div>
        <div class="span6">
            <table id="attributesList"></table> 
            <div id="attributesPager"></div>  

        </div>
    </div>
    <br />
    <div class="row">
        <div class="span6">

            <table id="ownersList"></table> 
            <div id="ownersPager"></div>
        </div>
    </div>

</div> <!-- /container -->
<script type="text/javascript">

    jQuery(document).ready(function(){

            var width = 560;
            //var width = 860;

            formatLink = function( cellvalue, options, rowObject )
            {
                //log(rowObject[0])
                return '<a href="#" class="actionEditOwner" data-id="'+rowObject[0]+'">Edit</a>';

                //return "<a href='#' onClick="+editObjectDialog(base_url)+";>" + cellvalue + "</a>";
            }

            // attach live event
            $('.actionEditOwner').live('click', function() { 
                    log($(this).attr('data-id')); 
            });

            jQuery("#hotelsList").jqGrid({ 
                    url:base_url+'home/getMyRowsObject?q=1', 
                    datatype: "json", 
                    colNames:['Rbr','Tip objekta', 'Ime', 'Status','Datum unosa','Vlasnik','Polja','Akcija'],  
                    colModel:[ 
                        {name:'ID',index:'ID', width:60, sorttype:"int",align:"left"}, 
                        {name:'type',index:'type', width:100}, 
                        {name:'name',index:'name', width:100}, 
                        {name:'status',index:'status', width:100, formatter:'select', editoptions:{value:"0:<span class='inactive'>Inactive</span>;1:<span class='active'>Active</span>"}}, 
                        {name:'date_time',index:'date_time', width:100}, 
                        {name:'owners_ID',index:'owners_ID', width:80, align:"right",sorttype:"float"}, 
                        {name:'fields',index:'fields', width:80,align:"right",sorttype:"float",sortable:false},
                        {name:'action',index:'action', width:80,align:"center",sorttype:"float",sortable:false}
                    ], 
                    rowNum:5, 
                    rowList:[5,10,25,50], 
                    pager: '#hotelsPager', 
                    sortname: 'ID', 
                    viewrecords: true, 
                    sortorder: "desc", 
                    caption: "Pregled hotela",
                    width:width
            }).navGrid('#hotelsPager',{edit:true,add:true,del:true,deltext:'Briši',deltitle:'Briši odabrani red.',delfunc:deleteRow},
                {},
                {},
                {
                    caption: "Briši objekat",
                    msg: "Da li ste sigurni?",
                    bSubmit: "Briši",
                    bCancel: "Otkaži",
                    closeOnEscape:true,
                    addtext: 'Briši objekat'
                }
            );                         

            jQuery("#attributesList").jqGrid({ 
                    url:base_url+'home/getMyRowsAttributes?q=2', 
                    datatype: "json", 
                    colNames:['Rbr','Tip podatka', 'Ime', 'Obavezan','Kreirao korisnik','Akcija'], 
                    colModel:[                        
                        {name:'ID',index:'ID', width:50, sorttype:"int"}, 
                        {name:'value',index:'value', width:100}, 
                        {name:'name',index:'name', width:130}, 
                        {name:'required',index:'required', width:50, align:"right",sorttype:"float",formatter:'select', editoptions:{value:"0:<span class='inactive'>No</span>;1:<span class='active'>Yes</span>"}}, 
                        {name:'custom',index:'custom', width:70,align:"right",sorttype:"float",sortable:false, formatter:'select', editoptions:{value:"0:<span class='inactive'>No</span>;1:<span class='active'>Yes</span>"}, search:false},
                        {name:'showlink', align:"right", formatter:formatLink,width:50, search:false},
                    ], 
                    rowNum:10, 
                    rowList:[5,10,25,50], 
                    pager: '#attributesPager', 
                    sortname: 'ID', 
                    viewrecords: true, 
                    sortorder: "desc", 
                    caption: "Pregled atributa",
                    width:width 
            }).navGrid('#attributesPager',{edit:false,add:false,del:true,deltext:'Briši',deltitle:'Briši odabrani red.',delfunc:deleteRow,reloadAfterSubmit:true},
                {},
                {},
                {
                    caption: "Briši atribut",
                    msg: "Da li ste sigurni?",
                    bSubmit: "Briši",
                    bCancel: "Otkaži",
                    closeOnEscape:true,
                    addtext: 'Briši atribut'
                }
            );                         

            /*jQuery("#ownersList").jqGrid({ 
            url:base_url+'home/getMyRowsOwners?q=1', 
            datatype: "json", 
            colNames:['ID','name', 'email', 'telephone','action'], 
            colModel:[ 
            {name:'ID',index:'ID', width:60, sorttype:"int"}, 
            {name:'name',index:'name', width:100}, 
            {name:'email',index:'email', width:100}, 
            {name:'telephone',index:'telephone', width:100,align:"right",sorttype:"float",sortable:false},
            {name:'action',index:'action', width:100,align:"center",sorttype:"float",sortable:false}
            ], 
            rowNum:5, 
            rowList:[5,10,25,50], 
            pager: '#ownersPager', 
            sortname: 'ID', 
            viewrecords: true, 
            sortorder: "desc", 
            caption: "Pregled vlasnika",
            width:width 
            }).navGrid('#ownersPager',{edit:false,add:false,del:false}); */

            function statusFormat( cellvalue, options, rowObject ){

                var frmValue;
                switch(cellvalue)
                {
                    case '0':  frmValue = 'Not active';
                        break;
                    case '1':  frmValue = 'Active'; 
                        break;
                }

                return '<span class="">'+frmValue+'</span>';

            }



            function deleteRow(id)
            {
                var grid = jQuery('#attributesList');
                var sel_id = grid.jqGrid('getGridParam', 'selrow');
                var myCellData = grid.jqGrid('getCell', sel_id, 'ID');

                var conf = confirm("Briši atribut sa rednim brojem "+myCellData+" ?")
                if (!conf){
                    return false;
                }

                $.ajax({
                        url: base_url+'attributes/delete/'+myCellData,
                        dataType: 'json',
                        type: "POST",
                        success: function (data, textStatus, xhr) {

                            if(data.action==true){

                                $('#attributesList').trigger( 'reloadGrid' );

                            }else
                                {
                                alert(data.msg,'error');
                            }
                        },
                        error: function (xhr, textStatus, errorThrown) 
                        {
                            alert('Error ocured...\n'+xhr+'\n'+textStatus+errorThrown+'\n','error');
                        }
                });

            }

    });

</script>

<style>

    .active{
        color:green !important;
    }
    .inactive{
        color:red !important; 
    }

</style>

<!--<style>
.ui-widget-content {
    border: 1px solid #FFFFFF;
}
.ui-jqgrid .ui-jqgrid-resize-ltr {
    display: none;
}
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
    background-image: -moz-linear-gradient(center top , #F9F9F9, #E3E4E6);
}
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
      box-shadow:none;
      background-image: -moz-linear-gradient(center top , #FFFFFF, #FFFFFF 25%, #E6E6E6) !important;
}
</style>-->